<template>
    <div class="e-table billList">
        <div class="top">
            <div class="left" style="margin-left: 10px">
                <div>
                    <el-button
                        size="mini"
                        @click="buttonAdd"
                        style="background: #7aa818; color: #fff"
                        >新增</el-button
                    >
                </div>
            </div>
            <div class="right">
                <div class="right-div1">
                    <el-input
                        placeholder=""
                        v-model="query.keyword"
                        size="small"
                        @select="onSearch"
                        @change="onSearch"
                    >
                    <img src="@/assets/search.png" slot="suffix" @click="onSearch" />
                    </el-input>
                </div>
                <div>
                    <el-button
                        size="small"
                        style="background: #2e61d7; color: #fff"
                        @click="onAdvanceSearch"
                        >高级搜索</el-button
                    >
                </div>
            </div>
        </div>
        <el-table
            border
            ref="table"
            :data="tableData"
            style="width: 100%"
            class="table"
            highlight-current-row
            v-sortTable="{ 'tableData': tableData, '_this': this, 'ref': 'table' }"
        >
            <el-table-column
                label="结算编号"
                min-width="170"
                fixed
                show-overflow-tooltip
            >
                <template slot-scope="scope">
                    <span
                        @click="Examine(scope.row)"
                        style="color: blue; cursor: pointer"
                    >
                        {{ scope.row.billNo }}
                    </span>
                </template>
            </el-table-column>
            <el-table-column
                fixed
                prop="settlementDate"
                label="结算日期"
                width="150">
            </el-table-column>
            <el-table-column
                prop="period"
                label="期数"
                min-width="200"
            >
            </el-table-column>
            <el-table-column
                prop="contractName"
                label="合同名称"
                min-width="150"
            >
            </el-table-column>
            <el-table-column
                prop="outsourcerName"
                label="外包方"
                min-width="100"
            >
            </el-table-column>
            <el-table-column
                prop="orgName"
                label="录入机构"
                width="100"
            >
            </el-table-column>
            <el-table-column
                prop="excludingDepositAmount"
                label="本期结算金额(不含保证金)"
                width="200"
            >
             </el-table-column>
             <el-table-column
                prop="taxAmount"
                label="税额"
                width="100"
            >
             </el-table-column>
            <el-table-column
                prop="totalAmount"
                label="本期结算金额(含税)"
                width="150"
            >
             </el-table-column>
               <el-table-column
                prop="currentTotalAmount"
                label="截止本期末累计结算金额(含税)"
                width="240"
            >
             </el-table-column>
            <el-table-column
            prop="state"
            label="状态"
            width="100">
                <template slot-scope="{ row,$index }">
                    <ToolHistory v-if="row.stateKey == 1" :key="$index" url="/projectsettle/flowEngin/getAuditHistory" :billId="row.billId" :billType="1095">
                        <span v-status="row.stateKey">
                          {{row.state}}
                        </span>
                    </ToolHistory>
                    <span v-else v-status="row.stateKey">
                       {{row.state}}
                    </span>
                </template>
            </el-table-column>
            <el-table-column
            prop="sendEasState"
            label="传输财务共享"
            show-overflow-tooltip
            width="120">
              <template slot-scope="{ row }">
                    <span v-if="row.sendEasState=='未传'||row.sendEasState=='返回修改'" class="redFont">{{row.sendEasState}}</span>
                    <span v-else class="greenFont">{{row.sendEasState}}</span>
              </template>
            </el-table-column>
        </el-table>
        <!-- 分页 -->
        <ComPagination
            :total="total"
            :pageSize.sync="query.limit"
            :currentPage.sync="query.page"
            @currentChange="getData"
            @sizeChange="getData"
            class="bottomSetting"
        />
    </div>
</template>
<script>
import ComPagination from '@/components/pagination/pagination.vue'
import { vueDom, debounce, advanceSearch } from '@/utils/common.js'
import request from '@/api/settlementManagement/otherSettlement/otherSettlement.js'
export default {
    components: {
        ComPagination,
    },
    data () {
        return {
            keyword: '',
            tableData: [],
            query: {
                'beginDate': '',
                'contractName': '',
                'endDate': '',
                'keyword': '',
                'limit': 20,
                'orgId': '',
                'outsourcerName': '',
                'page': 1,
                'sendEasStates': [],
                'states': []
            },
            total: 0,
            tableHeight: 0,
            auditParams: {
                billId: '',
                billType: 1095,
                freeNextUnitIndex: 0,
                freeNextUser: '',
                isPass: true,
                isShareInAudit: true,
                opinion: ''
            },
        }
    },
    computed: {
    },
    created () {
        this.getData()
    },
    mounted () {
        // table动态高度
        vueDom(
            () => {
                this.tableHeight = document.body.clientHeight - 240
            },
            () => {
                return $('table').length !== 0
            }
        )
        this.fn = () => {
            this.tableHeight = document.body.clientHeight - 240
        }
        window.onresize = debounce(this.fn)
    },
    methods: {
        // 获取列表数据
        async getData () {
            //接口非此模板接口需更换
            const res = await request.getListOtherSettlementData(this.query)
            const data = res.list || []
            //状态
            const obj = {
                '-1': '已删除',
                '0': '草稿',
                '1': '审核中',
                '2': '已审核',
                '5': '已作废'
            }
            data.forEach(item => {
                item.stateKey = item.state
                item.state = obj[item.state]
            })
            this.tableData = data
            this.total = res.totalCount
        },
        //新增按钮
        buttonAdd () {
            this.$router.push('/otherSettlementAdd')
        },
        //点击编号
        Examine (row) {
            if (row.stateKey == -1 || row.stateKey == 2 || row.stateKey == 5) {
                this.$router.push({
                    path: '/otherSettlementDetail',
                    query: { billid: row.billId }
                })
            } else {
                this.auditParams.billId = row.billId
                //非本模块接口需修改
                request.getButtonsTypeData(this.auditParams).then(res => {
                    if (res.canModify == true) {
                        this.$router.push({
                            path: '/otherSettlementEdit',
                            query: { billid: row.billId }
                        })
                    } else {
                        this.$router.push({
                            path: '/otherSettlementDetail',
                            query: { billid: row.billId }
                        })
                    }
                })
            }
        },
        onSearch () {
            this.getData()
        },
        onAdvanceSearch () {
            advanceSearch('/guochengJieshuanSearch')
                .then(res => {
                    this.query.keyword = ''
                    this.query.limit = 20
                    this.query.page = 1
                    const { orgId, outsourcerName, contractName,
                        states, sendEasStates, beginDate, endDate } = res
                    this.query.orgId = orgId
                    this.query.outsourcerName = outsourcerName
                    this.query.contractName = contractName
                    this.query.states = states
                    this.query.sendEasStates = sendEasStates
                    this.query.beginDate = beginDate
                    this.query.endDate = endDate
                    this.getData()
                })
        },
    }
}
</script>
<style lang="scss" scoped>
::v-deep.el-table .cell {
    text-align: center;
}

.e-table {
    min-height: 97.3vh;
}
</style>
